//
//package com.chen.config;
//
//import org.apache.catalina.Context;
//import org.apache.catalina.connector.Connector;
//import org.apache.tomcat.util.descriptor.web.SecurityCollection;
//import org.apache.tomcat.util.descriptor.web.SecurityConstraint;
//import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
//import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//
//
///**
// * @Author:chenao
// * @DATE:2022/4/6 22:16
// * 配置上线https，本地启动时全部注释
// */
//
//@Configuration
//public class TomcatConfig {
//    @Bean
//    public ServletWebServerFactory servletContainer() {
//
//        TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() {
//
//            @Override
//            protected void postProcessContext(Context context) {
//
//                SecurityConstraint securityConstraint = new SecurityConstraint();
//                securityConstraint.setUserConstraint("CONFIDENTIAL");
//                SecurityCollection collection = new SecurityCollection();
//                collection.addPattern("/*");
//                securityConstraint.addCollection(collection);
//                context.addConstraint(securityConstraint);
//            }
//        };
//        tomcat.addAdditionalTomcatConnectors(initiateHttpConnector());
//        return tomcat;
//    }
///**
// * 让我们的应用支持HTTP是个好想法，但是需要重定向到HTTPS，
// * 但是不能同时在application.properties中同时配置两个connector，
// * 所以要以编程的方式配置HTTP connector，然后重定向到HTTPS connector
// * @return Connector
// */
//
//    private Connector initiateHttpConnector() {
//        Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
//        connector.setScheme("http");
//        connector.setPort(81); // http端口
//        connector.setSecure(false);
//        connector.setRedirectPort(443); // application.properties中配置的https端口
//        return connector;
//    }
//
//}
//
